<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

	private $auth_token_info;

	public function index ()
	{

		$this->output->set_content_type('text/plain; charset=utf-8');
		var_dump($this->auth_token_info);

	}

	public function __construct ()
	{

		// parent constructor
		parent::__construct();

		// load helpers and models
		$this->load->helper('url');
		$this->load->model('auth/auth');

		// search cookies for auth token
		$auth_token = $this->input->cookie('auth_token');
		if ( ! is_string($auth_token) )
			redirect('admin/login');

		// validate auth token
		$this->auth_token_info = $this->auth->auth_token($auth_token);
		if (is_null($this->auth_token_info))
		{
			// destroy cookie
			$cookie = array(
				'name'   => 'auth_token',
				'value'  => NULL,
				'expire' => -3600,
				'path'   => '/'
			);
			$this->input->set_cookie($cookie);
			// redirect
			redirect('admin/login');
		}

	}

}
